package com.dl.service;

import com.dl.dao.CoursePlanMapper;
import com.dl.dao.TimesliceMapper;
import com.dl.pojo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class CoursePlanService {

    @Autowired
    private CoursePlanMapper coursePlanMapper;
    @Autowired
    private TimesliceMapper timesliceMapper;

    public int addCoursePlan_1(CoursePlan coursePlan){
        return coursePlanMapper.insertCoursePlan(coursePlan);
    }

    public int addCoursePlan_2(Integer setupid, Integer week, Integer day, Integer hour, Integer roomid){
        Timeslice timeslice = new Timeslice();
        timeslice.setWeek(week-1);
        timeslice.setDay(day-1);
        timeslice.setHour(hour-1);
        List<Timeslice> timeslices = timesliceMapper.selTimeslices(timeslice);

        CoursePlan coursePlan = new CoursePlan();
        coursePlan.setPlan_setupid(setupid);
        coursePlan.setPlan_timesliceid(timeslices.get(0).getTime_id());
        coursePlan.setPlan_roomid(roomid);
        return coursePlanMapper.insertCoursePlan(coursePlan);
    }

    public int addCoursePlan_4(Integer setupid, Integer week_0, Integer week_1, Integer day_0, Integer day_1, Integer hour_0, Integer hour_1, Integer roomid){
        List<Timeslice> timeslices = timesliceMapper.selTimeslicesByField(week_0-1, week_1-1, day_0-1, day_1-1, hour_0-1, hour_1-1);

        List<CoursePlan> coursePlans = new ArrayList<CoursePlan>();
        for(Timeslice timeslice:timeslices){
            CoursePlan coursePlan = new CoursePlan();
            coursePlan.setPlan_setupid(setupid);
            coursePlan.setPlan_roomid(roomid);
            coursePlan.setPlan_timesliceid(timeslice.getTime_id());
            coursePlans.add(coursePlan);
        }
        return coursePlanMapper.insertCoursePlans(coursePlans);
    }


}
